package com.example.authority.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.authority.domain.RoleMenu;
import com.example.authority.mapper.RoleMenuMapper;
import com.example.authority.service.RoleMenuService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author Limhuang
* @description 针对表【sys_role_menu】的数据库操作Service实现
* @createDate 2024-06-23 22:12:37
*/
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu>
    implements RoleMenuService {

    @Override
    public List<Long> getMenusByRole(Long roleId) {
        QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("SELECT DISTINCT menu_id");
        queryWrapper.lambda().eq(RoleMenu::getRoleId, roleId);
        List<RoleMenu> roleMenus = this.list(queryWrapper);
        List<Long> menuIds = new ArrayList<>();
        roleMenus.stream().forEach(roleMenu -> {
            menuIds.add(roleMenu.getMenuId());
        });
        return menuIds;
    }
}




